package Entity;

import java.sql.*;

public class DatabaseConnection {

// Sesuaikan properti jdbcURL dengan basis data anda
    private static String jdbcURL = "jdbc:oracle:thin:@localhost:1521:XE";
    private static String user = "perpus";
    private static String password = "library";
    private static Connection connection = null;
    private static PreparedStatement pstmt = null;

    public DatabaseConnection(String user, String password) {
        DatabaseConnection.user = user;
        DatabaseConnection.password = password;
    }

    public DatabaseConnection() {
    }

    public static Connection getConnection() {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            connection = DriverManager.getConnection(jdbcURL, user, password);
            System.out.println("Koneksi berhasil");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return connection;
    }
    

    public boolean isConnected() {
        if (connection != null) {
            return true;
        } else {
            return false;
        }
    }

    public boolean getClosed() {
        if (isConnected()) {
            try {
                connection.close();
                connection = null;
            } catch (SQLException ex) {
            }
            return true;
        } else {
            return false;
        }
    }

    public void setConn(Connection connection) {
        this.connection = connection;
    }
}
